<template>
	<view class="container">
		<!-- 用户信息 -->
		<view class="user-info">
			<view class="user-header">
				<image :src="userInfo.avatar" mode="aspectFill" class="avatar"></image>
				<view class="user-detail">
					<text class="nickname">{{userInfo.nickname}}</text>
					<text class="level">Level {{userInfo.level}}</text>
				</view>
			</view>
			<view class="user-stats">
				<view class="stat-item">
					<text class="num">{{userInfo.courseCount}}</text>
					<text class="label">在学课程</text>
				</view>
				<view class="stat-item">
					<text class="num">{{userInfo.studyTime}}</text>
					<text class="label">学习时长</text>
				</view>
				<view class="stat-item">
					<text class="num">{{userInfo.points}}</text>
					<text class="label">积分</text>
				</view>
			</view>
		</view>
		
		<!-- 功能菜单 -->
		<view class="menu-list">
			<view class="menu-group">
				<view class="menu-item" v-for="(item, index) in menuList1" :key="index" @tap="handleMenu(item)">
					<view class="menu-left">
						<image :src="item.icon" mode="aspectFit" class="menu-icon"></image>
						<text class="menu-text">{{item.name}}</text>
					</view>
					<image src="/static/icons/arrow-right.png" mode="aspectFit" class="arrow-icon"></image>
				</view>
			</view>
			
			<view class="menu-group">
				<view class="menu-item" v-for="(item, index) in menuList2" :key="index" @tap="handleMenu(item)">
					<view class="menu-left">
						<image :src="item.icon" mode="aspectFit" class="menu-icon"></image>
						<text class="menu-text">{{item.name}}</text>
					</view>
					<image src="/static/icons/arrow-right.png" mode="aspectFit" class="arrow-icon"></image>
				</view>
			</view>
		</view>
		
		<!-- 退出登录 -->
		<view class="logout-btn" @tap="handleLogout">
			<text>退出登录</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo: {
				avatar: '/static/user-avatar.png',
				nickname: '未登录',
				level: 1,
				courseCount: 0,
				studyTime: '0小时',
				points: 0
			},
			menuList1: [
				{ name: '我的课程', icon: '/static/icons/course.png', path: '/pages/my/course' },
				{ name: '学习记录', icon: '/static/icons/record.png', path: '/pages/my/record' },
				{ name: '我的收藏', icon: '/static/icons/favorite.png', path: '/pages/my/favorite' },
				{ name: '学生画像', icon: '/static/icons/analytics.png', path: '/pages/student-analytics/student-analytics' }
			],
			menuList2: [
				{ name: '消息通知', icon: '/static/icons/message.png', path: '/pages/my/message' },
				{ name: '设置', icon: '/static/icons/settings.png', path: '/pages/my/settings' },
				{ name: '关于我们', icon: '/static/icons/about.png', path: '/pages/my/about' }
			]
		}
	},
	onLoad() {
		// TODO: 获取用户信息
		this.getUserInfo()
	},
	methods: {
		getUserInfo() {
			// TODO: 调用接口获取用户信息
		},
		handleMenu(item) {
			uni.navigateTo({
				url: item.path
			})
		},
		handleLogout() {
			uni.showModal({
				title: '提示',
				content: '确定要退出登录吗？',
				success: (res) => {
					if (res.confirm) {
						// TODO: 执行退出登录
						uni.showToast({
							title: '退出成功',
							icon: 'success'
						})
					}
				}
			})
		}
	}
}
</script>

<style lang="scss">
.container {
	min-height: 100vh;
	background-color: #f5f5f5;
}

.user-info {
	background: linear-gradient(135deg, #018EFF, #00B4FF);
	padding: 20px;
	color: #ffffff;
	
	.user-header {
		display: flex;
		align-items: center;
		margin-bottom: 20px;
		
		.avatar {
			width: 60px;
			height: 60px;
			border-radius: 30px;
			margin-right: 15px;
		}
		
		.user-detail {
			.nickname {
				font-size: 18px;
				font-weight: bold;
				display: block;
				margin-bottom: 5px;
			}
			
			.level {
				font-size: 12px;
				background-color: rgba(255,255,255,0.2);
				padding: 2px 8px;
				border-radius: 10px;
			}
		}
	}
	
	.user-stats {
		display: flex;
		justify-content: space-around;
		
		.stat-item {
			text-align: center;
			
			.num {
				font-size: 20px;
				font-weight: bold;
				display: block;
				margin-bottom: 5px;
			}
			
			.label {
				font-size: 12px;
				opacity: 0.8;
			}
		}
	}
}

.menu-list {
	padding: 10px;
	
	.menu-group {
		background-color: #ffffff;
		border-radius: 12px;
		margin-bottom: 10px;
		
		.menu-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 15px;
			border-bottom: 1px solid #f5f5f5;
			
			&:last-child {
				border-bottom: none;
			}
			
			.menu-left {
				display: flex;
				align-items: center;
				
				.menu-icon {
					width: 20px;
					height: 20px;
					margin-right: 10px;
				}
				
				.menu-text {
					font-size: 16px;
					color: #333;
				}
			}
			
			.arrow-icon {
				width: 16px;
				height: 16px;
			}
		}
	}
}

.logout-btn {
	margin: 20px;
	height: 44px;
	line-height: 44px;
	text-align: center;
	background-color: #ffffff;
	border-radius: 22px;
	
	text {
		font-size: 16px;
		color: #ff6b6b;
	}
}
</style> 